package com.hh.system.service.impl;

import org.springframework.stereotype.Service;

import com.hh.baseframework.exception.MessageException;
import com.hh.system.bean.HhSysParam;

@Service
public class SysParamService extends BaseService<HhSysParam> {

	@Override
	public HhSysParam save(HhSysParam entity) throws MessageException {
		if (checkKeyOnly(entity)) {
			throw new MessageException("名称不能相同，请更换！");
		}
		HhSysParam hhSysParam = super.save(entity);
		 return hhSysParam;
	}

	private boolean checkKeyOnly(HhSysParam entity) {
		return this.dao
				.findWhetherData(
						"select count(o) from " +entity.getClass().getName() + " o "
								+ "where o.key=:key and (o.id!=:id or :id is null)",
								entity);
	}
	
}
